<template>
  <div class="demo">
    <div class="text-lg">VR 全景地图后台</div>
    <el-form ref='ruleFormRef' style='min-width: 300px' :model="ruleForm" :rules='rules' label-width='auto'
      class='demo-ruleForm mt-3' status-icon>
      <el-form-item label='' prop='userName'>
        <el-input v-model="ruleForm.userName" placeholder='账号' prefix-icon="user" />
      </el-form-item>
      <el-form-item label='' prop='password'>
        <el-input v-model="ruleForm.password" placeholder='密码' type="password" show-password prefix-icon="Lock"
          @keydown.enter="login" />
      </el-form-item>
    </el-form>

    <el-button type="primary" round style="width: 300px;" @click="login">登陆</el-button>
  </div>
</template>


<script setup lang='ts'>
import { reactive } from 'vue'
import { userLogin, userPermission } from '@/network/login'
import message from '@/hooks/message'
import { useRouter } from 'vue-router'
import useInfo from '@/store/user'

const router = useRouter()

const ruleForm = reactive({
  userName: '',
  password: ''
})
const rules = reactive({
  userName: [
    { required: true, message: '请输入账号', trigger: 'blur' }
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' }
  ]
})

const login = () => {
  userLogin(ruleForm).then(res => {
    if (res.code != 200) return
    useInfo().setToken(res.data.token)
    userPermission().then(result => {
      useInfo().setMenuList(result.data)
      useInfo().setActiveMenu('/home')
      message('登陆成功')
      router.push('/home')
    })
  })
}
</script>



<style lang='scss' scoped>
::v-deep .el-input__wrapper {
  border-radius: 50px !important;
}

.demo {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
</style>
